package com.coder;

import com.alibaba.fastjson.JSONObject;
import com.coderg.gmall.model.cart.CartInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import java.math.BigDecimal;

/**
 * @Description
 * @Author CoderG
 * @Date 2025/6/16 12:51
 **/
@RunWith(SpringRunner.class)
@SpringBootTest
public class Mytest {
    @Autowired
    RedisTemplate<Object,Object> redisTemplate;

    @Test
    public void testRedis() {
        String key = "user" + "cl" + "cart";
        CartInfo cartInfo = new CartInfo();
        cartInfo.setUserId("zs");
        cartInfo.setSkuPrice(new BigDecimal("1999.99"));
        cartInfo.setSkuNum(3);
        cartInfo.setIsChecked((short) 1);
        cartInfo.setSkuName("phone");
        cartInfo.setImgUrl("");
        cartInfo.setId(1L);
        cartInfo.setCartPrice(BigDecimal.valueOf(2999.99));

        redisTemplate.opsForHash().put(key, "1", JSONObject.toJSONString(cartInfo));

        redisTemplate.opsForHash().put(key, "2", cartInfo);
        // redisTemplate.opsForHash().put(key, 3, cartInfo);

        Object o = redisTemplate.opsForHash().get(key, "1");
        Object o1 = redisTemplate.opsForHash().get(key, "2");
        Object o2 = redisTemplate.opsForHash().get(key, "3");
        Object o3 = redisTemplate.opsForHash().entries(key+1);
        System.out.println(o);

    }
}
